package edu.uta.shorthorn.news.ui;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

public class YouTubeContent extends Activity {
	WebView webview;
	TextView textview;
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.newscontent);
	    
	    Intent webIntent = getIntent();
	    Bundle b = webIntent.getExtras();
	    
	    StringBuilder html = new StringBuilder();
	    html.append("<h2><font color=\"#5f5e5e\">").append(b.getString("title")).append("</h2></font>");
	    html.append("<p><i><font size=\"2\">").append(b.getString("pubDate")).append("</font></i></p><font color=\"#585757\">");
	    html.append(b.getString("author")).append("</p></font>");
	    html.append("<h3><a href=\"").append(b.getString("link")).append("\">Watch Now!</a></h3>");
	    //html.append(b.getString("content"));
	    
	    webview = new WebView(this);
	    webview = (WebView) findViewById(R.id.webview);
	    webview.loadData(html.toString(), "text/html", "UTF-8");
	    //webview.getSettings().setSupportZoom(true);
        //webview.getSettings().setBuiltInZoomControls(true);
	 }
	 
	   public boolean onCreateOptionsMenu(Menu menu){
	    	MenuInflater mi= getMenuInflater();
	    	mi.inflate(R.menu.share_menu, menu);
	    	return true;
	    }
	   
	   @Override
	   public boolean onOptionsItemSelected(MenuItem item) { 
	       switch (item.getItemId()) {
	           case R.id.twitter:
	        	   Intent webIntent = getIntent();
	        	   Bundle b = webIntent.getExtras();
	        	   String twitterUri = "http://m.twitter.com/?status=";
		        	String shareTwitterUri = Uri.encode(b.getString("link"));
		          Intent shareOnTwitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(twitterUri + shareTwitterUri));
		        	   startActivity(shareOnTwitterIntent);   
	                 break;
	           case R.id.facebook:
	        	   String facebookUri = "http://m.facebook.com/sharer.php?u=mytext";
		        	  // String link = url.getProtocol() + "://" + url.getHost() + "/" + (url.getPath() == null ? "" : url.getPath()) + (url.getQuery() == null ? "" : "?" + url.getQuery());
		        	   String shareFacebookUri = Uri.encode("http://www.theshorthorn.com/index.php/opinion/yourview/28570-columnist-lots-of-students-mouths-need-a-bar-of-soap");
		        	   Intent shareOnFacebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUri + shareFacebookUri));
		        	   startActivity(shareOnFacebookIntent); 
	                 break;
	       }
	       return true;
	   }
	    
	    
		public boolean onPrepareOptionsMenu(Menu menu){
			return true;
			
		}
}
